package com.sitia.jd.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.sitia.common.annotation.Log;
import com.sitia.common.core.controller.BaseController;
import com.sitia.common.core.domain.AjaxResult;
import com.sitia.common.enums.BusinessType;
import com.sitia.system.domain.MxCity;
import com.sitia.system.service.IMxCityService;
import com.sitia.common.utils.poi.ExcelUtil;
import com.sitia.common.core.page.TableDataInfo;
import org.springframework.web.multipart.MultipartFile;

/**
 * 城市Controller
 * 
 * @author sitia
 * @date 2023-07-16
 */
@RestController
@RequestMapping("/jd/city")
public class MxCityController extends BaseController
{
    @Autowired
    private IMxCityService mxCityService;

    /**
     * 查询城市列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MxCity mxCity)
    {
        startPage();
        List<MxCity> list = mxCityService.selectMxCityList(mxCity);
        return getDataTable(list);
    }

    @GetMapping("/cityList")
    public AjaxResult cityList(MxCity mxCity)
    {

        List<MxCity> list = mxCityService.selectMxCityList(mxCity);
        return AjaxResult.success(list);
    }
    /**
     * 导出城市列表
     */
    //@PreAuthorize("@ss.hasPermi('jd:city:export')")
    @Log(title = "城市", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MxCity mxCity)
    {
        List<MxCity> list = mxCityService.selectMxCityList(mxCity);
        ExcelUtil<MxCity> util = new ExcelUtil<MxCity>(MxCity.class);
        util.exportExcel(response, list, "城市数据");
    }

    /**
     * 获取城市详细信息
     */
    //@PreAuthorize("@ss.hasPermi('jd:city:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(mxCityService.selectMxCityById(id));
    }

    /**
     * 新增城市
     */
    @PreAuthorize("@ss.hasPermi('jd:city:add')")
    @Log(title = "城市", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MxCity mxCity)
    {
        return toAjax(mxCityService.insertMxCity(mxCity));
    }

    /**
     * 修改城市
     */
    @PreAuthorize("@ss.hasPermi('jd:city:edit')")
    @Log(title = "城市", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MxCity mxCity)
    {
        return toAjax(mxCityService.updateMxCity(mxCity));
    }

    /**
     * 删除城市
     */
    @PreAuthorize("@ss.hasPermi('jd:city:remove')")
    @Log(title = "城市", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(mxCityService.deleteMxCityByIds(ids));
    }


    /**
     * 上传excel
     */
    @PostMapping("/importBatchFill")
    public AjaxResult importExcel(MultipartFile file) {

        return AjaxResult.success(mxCityService.importExcelData(file));
    }

}
